<?php

namespace App\Admin\Controllers;

use App\Admin\Grid\NGrid;
use App\Models\AdjustmentModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid\Filter;

class UserAdjustmentController extends AdminController
{
    protected $title = '充值记录';

    protected function grid(): NGrid
    {
        $grid = new NGrid(new AdjustmentModel);
        $grid->model()->where([
            'adjustment.type' => 1
        ])->leftJoin('shop_user', 'shop_user.user_id', 'adjustment.user_id')
            ->leftJoin('shop_user as operate', 'operate.user_id', 'adjustment.operate_id')
            ->orderByDesc('adjustment.created_at')
            ->select([
                'adjustment.*',
                'shop_user.user_mobile',
                'operate.user_name'
            ]);

        $grid->filter(function (Filter $filter) {
            $filter->disableIdFilter();
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->equal('shop_user-user_mobile', '手机号')->mobile();
            });
        });
        $grid->column('id', 'ID')->sortable();
        $grid->column('user_mobile', __('shop_user.user_mobile'));
        $grid->column('amount', __('l.amount'));
        $grid->column('description', __('amount.description'));
        $grid->column('file_ids', __('amount.file_ids'))->display(function ($column) {
            return view('file_ids', ['id' => $this->id, 'images' => $column]);
        });
        $grid->column('extend', __('l.extend'));
        $grid->column('operate_id', __('l.operate_id'))->display(function () {
            return $this->user_name;
        });
        $grid->column('created_at', __('l.createdAt'));
        return $grid;
    }
}
